const userSignupTpl = require('../views/userSignup.html');

const userSignupController = {
    render({ res, router }) {
        res.render(userSignupTpl);
        this.signup(router);
    },
    signup(router) {
        $('#user-signup').click(() => {
            $.ajax({
                type: "post",
                url: "/interface/user/signup",
                data: {
                    username: $('#signup-username').val(),
                    password: $('#signup-password').val()
                },
                dataType: "json",
                success: function(res) {
                    if (res.rat) {
                        router.go('/user/signin');
                    } else {
                        alert('用户名已存在,请更换用户名重新注册');
                    }
                }
            });
        });
    }
}

module.exports = userSignupController;